package com.kk.springcloud.controller;

import com.kk.entities.CommResult;
import com.kk.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


/**
 * @author o_o
 */
@RestController
public class OrderController {

    private static final String PAYMENT_URL = "http://localhost:8001";
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/order/payment/create")
    public CommResult<Payment> create(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/create", payment, CommResult.class);
    }

    @GetMapping("/order/payment/get/{id}")
    public CommResult<Payment> get(@PathVariable("id") long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/get/" + id, CommResult.class);
    }
}
